package org.geektimes.projects.user.service;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.repository.DatabaseUserRepository;
import org.geektimes.projects.user.sql.DBConnectionManager;
import org.geektimes.projects.user.sql.LocalTransactional;
import org.geektimes.projects.user.sql.SimpleDBConnectionManager;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.validation.Validator;
import java.sql.Connection;
import java.sql.DriverManager;

public class UserServiceImpl implements UserService {

//    private DatabaseUserRepository databaseUserRepository;
//
//    public UserServiceImpl() {
//        this.initService();
//    }

//    private void initService() {
//        try {
//            databaseUserRepository = new DatabaseUserRepository();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    @Resource(name = "bean/EntityManager")
    private EntityManager entityManager;

    @Resource(name = "bean/Validator")
    private Validator validator;

    @Override
    @LocalTransactional
    public boolean register(User user) {
        entityManager.persist(user);
        update(user);
        return false;
        //return databaseUserRepository.save(user);
    }

    @Override
    public boolean deregister(User user) {
        return false;
    }

    @Override
    public boolean update(User user) {
        return false;
    }

    @Override
    public User queryUserById(Long id) {
        return null;
    }

    @Override
    public User queryUserByNameAndPassword(String name, String password) {
        return null;
    }
}
